package com.java3_3;

//懒汉单例模式
public class Demo2 {
    private String name;
    private int age;

    private Demo2(String name, int age) {
        this.name = name;
        this.age = age;
    }

    private static Demo2 demo2 = null;

    public static Demo2 getDemo2() {
        synchronized (Demo2.class) {
            if(demo2 == null){
                demo2 = new Demo2("lisi",22);
            }
        }
        return demo2;
    }
}
